﻿using System;
using System.Windows.Forms;
using AppAcc.Models;

namespace AppAcc.Views.DanhMuc
{
    public partial class FormNhomDoiTacThem : DevComponents.DotNetBar.RibbonForm
    {
        //private AppAccContext db = new AppAccContext();
        private PhanMenKeToanEntities1 db = new PhanMenKeToanEntities1();
        public FormNhomDoiTacThem()
        {
            InitializeComponent();
        }

        private void BttLuu_Click(object sender, EventArgs e)
        {
            Create();
            Reset();
            if (txtTenNhomDoiTac.Text != "")
            {
                BttLuu.Enabled = true;
            }
            else
            {
                BttLuu.Enabled = false;
            }
        }

        private void BttThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        void Create()
        {
            try
            {
                var ndt = new NhomDoiTac();
                ndt.TenNhomDoiTac = txtTenNhomDoiTac.Text;
                ndt.DienGiai = txtDienGiai.Text;
                db.NhomDoiTacs.Add(ndt);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

        }

        void Reset()
        {
            txtDienGiai.Text = "";
            txtTenNhomDoiTac.Text = "";
        }

        private void txtTenNhomDoiTac_TextChanged(object sender, EventArgs e)
        {
            if (txtTenNhomDoiTac.Text != "")
            {
                BttLuu.Enabled = true;
            }
            else
            {
                BttLuu.Enabled = false;
            }
        }

        private void txtDienGiai_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
